<template>
  <div class="date-range-picker-wrap">
    <el-date-picker
      v-if="!isExhibition"
      v-model="selectData"
      :disabled="disabled"
      value-format="timestamp"
      type="daterange"
      range-separator="-"
      start-placeholder="开始日期"
      end-placeholder="结束日期"
      format="yyyy/MM/dd" />
    <div v-if="isExhibition" class="date-info-text">
      <span v-if="selectData">{{ selectData[0] / 1000 | standardFormat('YYYY/MM/DD') }} - {{ selectData[1] / 1000 | standardFormat('YYYY/MM/DD') }}</span>
      <span v-if="selectData" style="color: #666;">{{ tip }}</span>
      <span v-else> -- </span>
    </div>
  </div>
</template>
<script>
import { standardFormat } from '@/filters/date';
export default {
  name: 'DateRangePicker',
  filters: {
    standardFormat
  },
  model: {
    prop: 'params',
    event: 'change'
  },
  props: {
    params: {
      type: String | Array,
      default: () => {
        return null;
      }
    },
    moduleName: {
      type: String,
      default: ''
    },
    disabled: {
      type: Boolean,
      default: false
    },
    tip: {
      type: String,
      default: '（合同起止时间）'
    },
    isExhibition: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    selectData: {
      get() {
        return this.params;
      },
      set(val) {
        this.$emit('change', val);
      }
    }
  }
};
</script>
<style lang="scss" scoped>
.date-range-picker-wrap {
  display: flex;
  align-items: center;
  .tip {
    color: #606266;
  }
}
::v-deep .el-range-separator {
  padding: 0;
}
::v-deep .el-range-input {
  font-size: 14px;
}
.date-info-text {
  line-height: 1.2;
  padding-top: 8px;
}
</style>
